<template>
  <a-button @click="countDown">Open modal to close in 3s</a-button>
</template>
<script lang="ts">
import { Modal } from 'ant-design-vue';
import { defineComponent,onMounted,onBeforeUnmount } from 'vue';
import Bus from '@/mitt/index'
export default defineComponent({
  setup() {
    const countDown = () => {
      let secondsToGo = 3;
      const modal = Modal.success({
        title: '温馨提示',
        content: `这条会员的消息已经被彻底删除,无法复原,将于${secondsToGo}秒后面返回页面`,
      });
      const interval = setInterval(() => {
        secondsToGo -= 1;
        modal.update({
          content: `这条会员的消息已经被彻底删除,无法复原,将于${secondsToGo}秒后面返回页面`,
        });
      }, 1000);
      setTimeout(() => {
        clearInterval(interval);
        modal.destroy();
      }, secondsToGo * 1000);
    };
    onMounted(() => {
      Bus.on('del', countDown)
    })
    onBeforeUnmount(() => {
      Bus.off('del', countDown)
    })
    return {
      countDown,
    };
  },
});
</script>
